package cn.semes.org.dto;

import cn.semes.org.domain.Employee;
import cn.semes.org.domain.Shop;
import com.fasterxml.jackson.databind.util.BeanUtil;
import lombok.Data;
import org.springframework.beans.BeanUtils;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
public class ShopSettlementDto {

    @NotBlank(message = "店铺姓名不能为空")
    private String name;

    private Long id;
    @NotBlank(message = "店铺电话不能为空")
    private String tel;

    @NotBlank(message = "店铺地址不能为空")
    private String address;

    private String logo; // 店铺头像嘛，可以用默认的

    @Valid
    private EmployeeDto admin;

    public Shop getShop() {
        return Shop.builder() // Shop.builder() 这里可以写赋值 .build(); ,使用此方法类中必须要有@Builder注释
                .id(this.getId())
                .name(this.getName())
                .tel(this.getTel())
                .address(this.getAddress())
                .logo(this.getLogo())
                .registerTime(new Date())
                .state(0)
                .build();
    }

    public Employee getEmployee() {
        Employee employee = new Employee();

        // 对象复制，必须字段要求一样，通过反射赋值
        BeanUtils.copyProperties(admin, employee);
        employee.setAge(16);
        employee.setState(1); // 赋值默认状态
        return employee;
    }

}
